/**
 * 
 */
package org.dc.agent.manager;

import org.apache.log4j.Logger;
import org.dc.agent.util.JobUtil;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.transport.DefaultUdpTransportMapping;

import java.io.IOException;

/**
 * @author 徐春鹏 日期 2012-11-9
 */
public class SnmpManager {

	private static Logger logger = Logger.getLogger(SnmpManager.class);

	private static Snmp snmp;

	public static void main(String[] args) {

		JobUtil jobUtil = new JobUtil();
		boolean initSnmp = SnmpManager.initSnmp();
		if (initSnmp) {

			logger.warn("初始化SNMP成功准备加载任务 -- init SNMP success ,ready to load jobs");
			jobUtil.loadJobs(snmp);
			boolean activeJobs = jobUtil.ActiveJobs();
			if (activeJobs) {
				logger.warn("激活成功  -----   active jobs success");
			}
		}

	}

	private static boolean initSnmp() {
		// 初始化SNMP

		try {
			@SuppressWarnings("rawtypes")
			TransportMapping defaultUdpTransportMapping = new DefaultUdpTransportMapping();
			snmp = new Snmp(defaultUdpTransportMapping);
			defaultUdpTransportMapping.listen();

			return true;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return false;
	}
}
